@include('widget.admin.adminnav',['url'=>'/index.php/admin/scene/list','name'=>$type=='edit'?'编辑景区':'添加景区','title'=>'景区管理'])
<style>
    h1,h2,h3,h4,h5,h6{
        font-size: 16px;
    }
    .sceneCover{
        display: inline-block;
        width: 150px;
        height: 100px;
    }
    .w-e-droplist{
        width:60px;
    }
</style>
<form class="form-horizontal" role="form" id="adminMessage">
    <input type="hidden" id="id" name="id" value="{{$id or 'new'}}">
    <input type="hidden" class="load-intro" value="{{$intro or ''}}">
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">景区名称</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" id="name" value="{{$name or ''}}" placeholder="请输入景区名称">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">景区地址</label>
        <div class="col-sm-6">
            <select class="form-control" id="getAreaId">
                <option disabled selected>选择</option>
                @foreach($allArea as $area)
                    <option value="{{$area->id}}" {{$area->id==$area_id?'selected':''}}>{{$area->name}}</option>
                @endforeach
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="price" class="col-sm-2 control-label">景区价格</label>
        <div class="col-sm-6">
            <input type="number" class="form-control" id="price" value="{{$price or ''}}" placeholder="请输入景区价格/元">
        </div>
    </div>
    <div class="form-group">
        <label for="price" class="col-sm-2 control-label">景区简介</label>
        <div class="col-sm-6">
            <!--编辑器位置-->
            <div id="editor">
            </div>
        </div>
    </div>
    <div class="form-group">
        @include('widget.upload',['bindBtn'=>'scene-cover','uploadTitle'=>'上传封面',
        'backPath'=>'scene-cover-path','showContent'=>'sceneCover','defaultImg'=>isset($cover)?$cover:null,'editPath'=>isset($cover)?$cover:''])
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10"  style="margin-top: 10px;">
            <button type="button" class="btn btn-primary" onclick="sceneHandler()">提交</button>
            <button type="reset" class="btn btn-default">重填</button>
        </div>
    </div>
</form>
<script>
    var E = window.wangEditor;
    var editor = new E('#editor');
    editor.customConfig.menus = [
        'head', 'bold', 'italic', 'underline',
        'strikeThrough',  'quote', 'image',, 'undo', 'redo'
    ];
    editor.customConfig.uploadImgShowBase64 = true;   // 使用 base64 保存图片
    editor.customConfig.uploadImgParams = {
        _token: '{{csrf_token()}}'  // 属性值会自动进行 encode ，此处无需 encode
    };
    editor.customConfig.debug = true;
    // 隐藏“网络图片”tab
    editor.customConfig.showLinkImg = false;
    editor.customConfig.customUploadImg = function (files, insert) {
        // files 是 input 中选中的文件列表
        // insert 是获取图片 url 后，插入到编辑器的方法
        var formData = new FormData();
        formData.append("file", files[0]);
        $.ajax({
            url: '/index.php/image/upload',
            type: "post",
            data: formData,
            dataType: "json",
            cache: false,
            contentType: false,
            processData: false
            , success: function (data) {
                insert(data.path)
            }, error: function () {

            }
        });
    };
    editor.create();
    $(".w-e-menu").css('z-index','10');
    $(".w-e-text-container").css('z-index','9');
    editor.txt.html($(".load-intro").val());
    function sceneHandler() {
        var event = event || window.event;
        event.preventDefault(); // 兼容标准浏览器
        window.event.returnValue = false; // 兼容IE6~8
        var _data = {
            id : $("#id").val(),
            name: $("#name").val(),
            area_id : $("#getAreaId  option:selected").attr('value'),
            price : $("#price").val(),
            intro : editor.txt.html(),
            cover : $("#scene-cover-path").val()
        };
        var Url="/index.php/admin/scene/save";
        dialog.confirm("确认保存？",function callback(){
            $.ajax({
                type:"post",
                data:_data,
                url:Url,
                dataType:"json",
                success:function(data){
                    if(data.res==1){
                        var _url="/index.php/admin/scene/list";
                        dialog.success("操作成功！",_url);
                    }else{
                        dialog.error(data.msg);
                    }
                }
            });
        });
    }
</script>